package top.swimmer.tools.data.sort;

import java.util.Arrays;

public class BubbleSort {
    public static void bubbleSort(int[] array) {
        if (array == null || array.length <= 1) {
            return;
        }

        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array.length - i - 1; j++) {
                if (array[j+1] < array[j]) {
                    int tmp = array[j+1];
                    array[j+1] = array[j];
                    array[j] = tmp;
                }
            }
        }
    }

    public static void main(String[] args) {
        int[] array = new int[]{8,2,3,4,1,5,1,6,3,9,12,41,4,56,31,52};
        bubbleSort(array);
        System.out.println(Arrays.toString(array));
    }
}
